var page = GetQueryString("page") == null ? 1 : parseInt(GetQueryString("page"));
// page = GetQueryString("page")==""?1:parseInt(GetQueryString("page"));
var limit = GetQueryString("limit") == null ? 10 : parseInt(GetQueryString("limit"));
// limit = GetQueryString("limit")==""?10:parseInt(GetQueryString("limit"));
var projectName = GetQueryString("projectName") == null ? "" : GetQueryString("projectName");
var type = GetQueryString("type") == null ? 0 : parseInt(GetQueryString("type"));

getProjectList(page, limit, projectName, type);

function getProjectList(page, limit, keyword, type) {
    // alert(decodeURI(keyword));
    console.log(page, limit, decodeURI(keyword), type);
    $.ajax({
        url: "/home/getAllProjectLimit",
        data: {'page': page, 'limit': limit, 'name': keyword, 'projectType.typeId': type},
        success: function (data) {
            new Vue({
                el: '#zc_list',
                data: {"data": data.data}
            });
            layui.use(['laypage', 'layer'], function () {
                var laypage = layui.laypage
                    , layer = layui.layer;
                var page=GetQueryString("page")==null?1:GetQueryString("page");
                laypage.render({
                    elem: 'page',
                    count: data.count,
                    curr: page,
                    theme: '#FFB800',
                    layout: ['count', 'prev', 'page', 'next', 'skip'],
                    jump: function(obj){
                        console.log(obj.curr);

                        if (page!=obj.curr)
                        window.location.href="list.html?projectName="+GetQueryString("projectName")+"&page="+obj.curr+"&limit="+GetQueryString("limit")
                            +"&type="+GetQueryString("type");

                    }
                });

            });

        }
    });
}

getAllProjectType();

function getAllProjectType() {
    $.ajax({
        url: "/home/getAllProjectType",
        success: function (data) {
            var html = "";

            $.each(data, function (k, d) {
                if (d.typeId==GetQueryString("type")){
                    $("#href-type").text(d.typeName);
                }

                var bt_class = "";
                switch (Math.ceil(Math.random() * 4)) {
                    case 1:
                        bt_class = "layui-btn-danger";
                        break;
                    case 2:
                        bt_class = "layui-btn-warm";
                        break;
                    case 3:
                        bt_class = "layui-btn-primary";
                        break;
                    case 4:
                        bt_class = "layui-btn-normal";
                        break;
                }
                html += "<span onclick=\"hrefTo(1,10,''," + d.typeId + ")\" class='layui-btn layui-btn-sm " + bt_class + "' style='margin: 5px'>" + d.typeName + "</span>";
            });
            if (GetQueryString("type")==0) $("#href-type").text("全部");
            console.log(data);
            $("#projectType").append(html);

        }
    });
}


function hrefTo(page, limit, keyword, type) {
    // alert(encodeURI(keyword));
    window.location.href = "list.html?projectName=" + encodeURI(keyword) + "&page=" + page + "&limit=" + limit + "&type=" + type;
}